package com.fita.entity.coupon;

import com.alibaba.fastjson.annotation.JSONField;
import com.demo2do.core.format.PersistentFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 优惠券模板
 * 
 * @author LZJ
 */
@Entity
@Table(name = "coupon_template")
@PersistentFormat
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class CouponTemplate {

    @Id
    @GeneratedValue
    private Long id;

    /** 优惠券名称*/
    private String name;

    /** 优惠券面值 */
    private Integer amount;
    
    /** 最低消费金额 */
    private Integer minAmount;
    
    /** 抵扣类型 */
    @Enumerated(EnumType.ORDINAL)
    private DiscountType discountType;

    /** 创建时间 */
    private Date createTime;

    /** 是否删除 */
    @Column(name = "is_disabled")
    @JSONField(serialize = false)
    private boolean disabled;

    /** 是否可转赠 */
    @Column(name = "is_give_available")
    private boolean giveAvailable;

    /** 使用规则 */
    @org.hibernate.annotations.Type(type = "text")
    private String description;

    /**
     * default constructor
     */
    public CouponTemplate() {
    }
    
    /**
     * 
     * @param inputAmount
     * @param inputMinAmount
     * @return
     */
    public CouponTemplate initialize(BigDecimal inputAmount, BigDecimal inputMinAmount) {
        this.createTime = new Date();
        this.amount = inputAmount == null ? null : inputAmount.multiply(new BigDecimal("100")).intValue();
        this.minAmount = inputMinAmount == null ? null : inputMinAmount.multiply(new BigDecimal("100")).intValue();
        return this;
    }
    
    /**
     * 
     * @param inputName
     * @param inputAmount
     * @param inputMinAmount
     * @return
     */
    public CouponTemplate edit(String inputName, BigDecimal inputAmount, BigDecimal inputMinAmount) {
        this.name = inputName;
        this.amount = inputAmount == null ? null : inputAmount.multiply(new BigDecimal("100")).intValue();
        this.minAmount = inputMinAmount == null ? null : inputMinAmount.multiply(new BigDecimal("100")).intValue();
       
        return this;
    }

    /**
     * 
     * @param description
     * @return
     */
    public CouponTemplate editDescription(String description) {
        this.description = description;
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the amount
     */
    public Integer getAmount() {
        return amount;
    }

    /**
     * @return the minAmount
     */
    public Integer getMinAmount() {
        return minAmount;
    }

    /**
     * @return the discountType
     */
    public DiscountType getDiscountType() {
        return discountType;
    }



    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @return the giveAvailable
     */
    public boolean isGiveAvailable() {
        return giveAvailable;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param amount the amount to set
     */
    public void setAmount(Integer amount) {
        this.amount = amount;
    }

    /**
     * @param minAmount the minAmount to set
     */
    public void setMinAmount(Integer minAmount) {
        this.minAmount = minAmount;
    }

    /**
     * @param discountType the discountType to set
     */
    public void setDiscountType(DiscountType discountType) {
        this.discountType = discountType;
    }


    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

    /**
     * @param giveAvailable the giveAvailable to set
     */
    public void setGiveAvailable(boolean giveAvailable) {
        this.giveAvailable = giveAvailable;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }
}
